const Mock = require('mockjs');

function login(req, res) {
  const { username, password } = req.body;

  // 模拟登录逻辑
  if (username === 'admin' && password === '123456') {
    const data = Mock.mock({
      code: 200,
      message: '登录成功',
      token: '@guid', // 生成一个随机的 token
      data: {
        id: '@id',
        name: '@cname',
        email: '@email',
        avatar: '@image("100x100")'
      }
    });
    res.json(data);
  } else {
    res.status(401).json({
      code: 401,
      message: '用户名或密码错误'
    });
  }
}

module.exports = login;
